#ifndef __STD_H
#define __STD_H

#include "main.h"
#include "MC33879.h"
#include "MC33972.h"
#include "ads7867.h"
#include "DAC8760.h"
#include "ads8684.h"

#ifndef true
#define true 1
#endif

#ifndef false
#define false 0
#endif

#ifndef bool
#define bool uint8_t
#endif

#define M_SET_BIT(REG, BIT) ((REG) |= (1UL << BIT))
#define M_CLR_BIT(REG, BIT) ((REG) &= ~(1UL << BIT))
#define M_READ_BIT(REG, BIT) ((REG >> BIT) & (1UL))

#define GROOUP_MAX 2
#define IO_IN_MAX 8

/* 硬件芯片错误*/
enum eDevErrType
{
    e_err_io_out = 0,
    e_err_io_in,
    e_err_outputcurrent,
    e_err_dac,
    e_err_adc,
    e_err_max31865,
    e_err_max31856,
};

enum eControlMode
{
    // 手动开始
    // 手动结束
    // 自动开始
    e_ControlMode_ManualEnd = 0,
    e_ControlMode_ManualStart = 1,
    e_ControlMode_AutoStart = 2

};
/* 传感器类型选择 */
enum eSensorType
{
    // 模拟电压型 0-10.24V
    e_SensorType_AnalogVoltage_10V = 0,
    // 模拟电流型 0-24mA
    e_SensorType_AnalogCurrent_24mA = 1,
    // 主机输入
    e_SensorType_Master = 2,
};

enum eError
{
    e_err_ok,
    e_err_spibusy,
};

typedef struct
{
    int32_t tx_current_pressure;

    int32_t rx_current_pressure;

    uint16_t control_mode;
    int32_t target_pressure;
    uint16_t float_threshold;
    uint8_t sensor_type;
    uint8_t max_power;
    float P;
    float I;
    float D;
    uint32_t sensor_min;        // 传感器量程最小值 单位Pa
    uint32_t sensor_max;        // 传感器量程最大值 单位Pa
    uint16_t sensor_signal_min; // 传感器信号最小值 单位mV/uA
    uint16_t sensor_signal_max; // 传感器信号最大值 单位mV/uA

    int32_t current_pressure; // 当前压力
    uint16_t analog_in_value; // adc值

    // 用于周期性轮询输入
    uint16_t tick;
    uint32_t temtime;

    uint32_t err;

} t_group;

typedef struct
{
    t_group group[GROOUP_MAX];
    uint8_t spi_busy;
} t_ethcat_dev, *p_ethcat_dev;

void ethercat_sync(p_ethcat_dev ptl);

#endif
